// component/header/header.js
var config = require("../../utils/config.js");
var network = require("../../utils/network.js");
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    id:'',  //客户id
    address:'',
    nickName:''
  },
  ready(){
    this.setData({
      id:wx.getStorageSync("userInfo").id,
      nickName: wx.getStorageSync("userInfo").nickName
    })
    this.getAddress();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getAddress(){
     
    },
    getAddress: function () {
      console.log(1)
      var p = new Promise( (resolve, reject)=> {
        wx.request({
          url: config.host + 'api_address/addressDefault',
          method: "POST",
          data: { id: this.data.id},
          success: res => {
            console.log(res.data.data)
            if (res.data.code == 99) {
              this.setData({
                address: res.data.data
              })
              resolve(res.data.data.m);
            } else if (res.code == 97) {
              this.setData({
                address: ''
              })
            }
            wx.setStorageSync("address", { "address": this.data.address, "m": this.data.address.m })
          }
        })
      })
      return p;
    },
    gotoMember(){
      wx.navigateTo({
        url: '/pages/member/member',
      })
    },
    gotoEditAddress(){
      wx.navigateTo({
        url: '/pages/editAddress/editAddress',
      })
    },
    gotoEditAddress1(){
      let data = JSON.stringify(this.data.address)
      wx.navigateTo({
        url: '/pages/editAddress/editAddress?data='+data,
      })
    }
  }
})
